package DesignPattern;

public class DesignPatternTest {

    /**
     * 单例模式
     * @param args
     */
//    public static void main(String[] args) {
//        SingletonPattern instance1 = SingletonPattern.getInstance();
//        SingletonPattern instance2 = SingletonPattern.getInstance();
//        SingletonPattern instance3 = SingletonPattern.getInstance();
//
//        System.out.println("Instance 1 HashCode: " + instance1.hashCode());
//        System.out.println("Instance 2 HashCode: " + instance2.hashCode());
//        System.out.println("Instance 3 HashCode: " + instance3.hashCode());
//
//        // 比较实例是否相同
//        if (instance1 == instance2 && instance2 == instance3) {
//            System.out.println("All instances are the same. Singleton pattern is working.");
//        } else {
//            System.out.println("Instances are different. Singleton pattern is not working.");
//        }
//    }

    /**
     * 工厂模式
     * @param args
     */
//    public static void main(String[] args) {
//        FactoryMethodPattern factoryMethodPattern = new FactoryMethodPattern();
//
//        FactoryMethodPattern.CreatorA creatorA = factoryMethodPattern.new CreatorA();
//        FactoryMethodPattern.Product productA = creatorA.factoryMethod();
//        productA.use(); // 输出: Using Product A
//
//        FactoryMethodPattern.CreatorB creatorB = factoryMethodPattern.new CreatorB();
//        FactoryMethodPattern.Product productB = creatorB.factoryMethod();
//        productB.use();
//
//        if (productA.getClass() != productB.getClass()) {
//            System.out.println("Different products are created. Factory Method pattern is working.");
//        } else {
//            System.out.println("Same products are created. Factory Method pattern is not working.");
//        }
//    }

    /**
     * 抽象工厂模式
     * @param args
     */
    public static void main(String[] args) {

        AbstractFactoryPattern.ConcreteFactoryA factoryA = new AbstractFactoryPattern().new ConcreteFactoryA();
        AbstractFactoryPattern.Product productA = factoryA.createProduct();
        productA.use(); // 输出: Using ConcreteProductA

        AbstractFactoryPattern.ConcreteFactoryB factoryB = new AbstractFactoryPattern().new ConcreteFactoryB();
        AbstractFactoryPattern.Product productB = factoryB.createProduct();
        productB.use(); // 输出: Using ConcreteProductA

        if (productA.getClass() != productB.getClass()) {
            System.out.println("Different products are created. Factory Method pattern is working.");
        } else {
            System.out.println("Same products are created. Factory Method pattern is not working.");
        }
    }

}
